<template>
    <div class="good-main">
        <router-link class="goodsitem" v-for="item in goods" :key="item.id" :to="'/home/goodslist/goodinfo/'+item.id">
            <img :src="item.img_url" alt="">
            <h3>{{item.title}}</h3>
            <div class="sell">
                <p class="price">
                    <span class="new">¥{{item.sell_price}}</span>
                    <span class="old">¥{{item.market_price}}</span>
                </p>
                <p class="num">
                    <span>热卖中</span>
                    <span>剩{{item.stock_quantity}}件</span>
                </p>
            </div>

        </router-link>

        <mt-button type="danger" size="large" @click="getmore()">加载更多</mt-button>

    </div>
</template>

<script>
    import axios from "axios"

    export default {
        name: "goodslist",
        data(){
            return{
                index : 1,
                goods: []
            }
        },
        methods:{
            getgoods(){
                axios.get("api/getgoods?pageindex="+this.index)
                    .then(suc=>{
                        // console.log(suc)
                        this.goods = this.goods.concat(suc.data.message)
                    })
                    .catch(err=>{
                        console.log(err)
                    })
            },
            getmore(){
                this.index ++
                this.getgoods()
            }
        },
        created(){
            this.getgoods()
        }

    }
</script>

<style scoped lang="less">
    .good-main{
        display: flex;
        justify-content: space-between;
        flex-wrap:wrap;
        padding: 10px;

        .goodsitem{
            width: 49%;
            border: 1px solid #ccc;
            box-shadow: 0 0 8px #ccc;
            margin-bottom: 6px;
            padding: 2px;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            /*min-height: 383px;*/

            img{
                width: 100%;
                /*vertical-align: middle;*/
                /*display: block;*/
            }

            h3{
                font-size: 14px;
                margin: 0;
                padding: 0;
            }
            .sell{
                background-color: #cccccc;
                p{
                    margin: 0;
                    padding: 4px;
                    font-size: 13px;
                }
                .price{
                    .new{
                        color:red;
                        font-size: 16px;
                        /*font-weight: bold;*/
                    }
                    .old{
                        text-indent: 20px;
                        text-decoration: line-through;
                        margin-left: 10px;
                    }

                }
                .num{
                    display: flex;
                    justify-content: space-between;
                }
            }

        }
    }
</style>